package com.idol.util;

import com.idol.annotation.Autowired;

import java.sql.SQLException;

/**
 * @author Supreme_Sir
 * @version 1.0
 * @className TransactionManager
 * @description 事务管理工具
 * @date 2020/10/13 10:28
 **/
public class TransactionManager {
    @Autowired
    private ConnectionUtil connectionUtil;

    /**
     * 开启事务
     * @throws SQLException
     */
    public void openTransaction() throws SQLException {
        connectionUtil.getCurrentThreadConn().setAutoCommit(false);
    }

    /**
     * 提交事务
     * @throws SQLException
     */
    public void commit() throws SQLException {
        connectionUtil.getCurrentThreadConn().commit();
    }

    /**
     * 回滚事务
     * @throws SQLException
     */
    public void rollback() throws SQLException {
        connectionUtil.getCurrentThreadConn().rollback();
    }
}
